﻿//JumbotCms_4.1 Final
using System;
using JumbotCms.Common;

namespace JumbotCms.WebFile.User
{
    public partial class _friendadd : JumbotCms.API.UserCenter
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            User_Load("", "html");
            if (q("act") != "save")
                Response.Write(GetPageHtml("user_friendadd"));
            else
            {
                if (!CheckFormUrl())
                    Response.End();
                if (Str2Str(f("txtUserId")) != "0" && f("txtUserName").Length > 0)
                {
                    doh.Reset();
                    doh.ConditionExpress = "friendid=@friendid and userid=@userid";
                    doh.AddConditionParameter("@friendid", Str2Str(f("txtUserId")));
                    doh.AddConditionParameter("@userid", UserId);
                    if (doh.Exist("jcms_normal_user_friends"))
                        Response.Write("JumbotCms.Alert('对方已是你好友', '0');");
                    else
                    {
                        string uId = Str2Str(f("txtUserId"));
                        doh.Reset();
                        doh.AddFieldItem("FriendId", uId);
                        doh.AddFieldItem("UserId", UserId);
                        doh.AddFieldItem("AddDate", DateTime.Now.ToString());
                        doh.Insert("jcms_normal_user_friends");
                        SendNotite("加好友", "<a href=\"javascript:void(0);\" onclick=\"ShowUserPage(" + UserId + ");\">" + UserName + "</a> 把你加为了好友", uId, "friend");

                        Response.Write("location='" + site.Dir + "user/friendlist';");
                    }
                }
                else
                    Response.Write("JumbotCms.Alert('提交有误', '0');");
            }
        }
    }
}
